package com.admin.business.background.venusWxOpenid;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: appwx授权登录openId记录表
 * @create: 2023-10-23 14:31:53
 **/
@Service("venusWxOpenidService")
@Slf4j
public class VenusWxOpenidService{

    @Resource
    VenusWxOpenidDao venusWxOpenidDao;

    /**
     * 添加appwx授权登录openId记录表,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:用户id
     *                   - user_open_id:微信openid
     *                   - state:1pc端 2 业主端 3 员工端 4 助业网
     *                   - nickName:微信用户名
     *                   - avatarUrl:微信用户头像
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return addVenusWxOpenid(CDO cdoRequest) {
        venusWxOpenidDao.addVenusWxOpenid(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新appwx授权登录openId记录表数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:用户id
     *                   - user_open_id:微信openid
     *                   - state:1pc端 2 业主端 3 员工端 4 助业网
     *                   - nickName:微信用户名
     *                   - avatarUrl:微信用户头像
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return updateVenusWxOpenidById(CDO cdoRequest) {
        venusWxOpenidDao.updateVenusWxOpenidById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除appwx授权登录openId记录表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return deleteVenusWxOpenidById(CDO cdoRequest){
        int count = venusWxOpenidDao.deleteVenusWxOpenidById(cdoRequest.getLong("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除appwx授权登录openId记录表数据
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return deleteVenusWxOpenid(CDO cdoRequest) {
        int count = venusWxOpenidDao.deleteVenusWxOpenid(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取appwx授权登录openId记录表数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return getVenusWxOpenidById(CDO cdoRequest) {
        CDO cdoMapperResult = venusWxOpenidDao.getVenusWxOpenidById(cdoRequest.getLong("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取appwx授权登录openId记录表数据列表
     *
     * @param cdoRequest
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return getVenusWxOpenidListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusWxOpenidDao.getVenusWxOpenidListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusWxOpenidDao.getVenusWxOpenidCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取appwx授权登录openId记录表数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author Ht
     * @create: 2023-10-23 14:31:53
     */
    @OpenApi
    public Return getVenusWxOpenidListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusWxOpenidDao.getVenusWxOpenidListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusWxOpenidDao.getVenusWxOpenidCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
